package nio;

import java.nio.IntBuffer;

public class BufferTest {
    public static void main(String[] args) {
        int capacity = 10;
        IntBuffer intBuffer = IntBuffer.allocate(capacity);
        // 向 buffer 中写入数据
        for (int i = 0; i < capacity; i++) {
            intBuffer.put(i);
        }
        // 读写切换
        intBuffer.flip();
        while (intBuffer.hasRemaining()) {
            System.out.println(intBuffer.get());
        }
    }
}
